
import {  ref } from 'vue';
//import {updateEntity, deleteEntity, getPersons} from '@/api/baseinfo/persons';
import { Modal } from '@arco-design/web-vue';
import { validateForm } from '@/utils';

export let modalType = ref(0);
export let currRecord = ref({} as any);


export function addNew () {
    modalType.value = 3;
    currRecord.value = {
        enabled: true
    };
    validateForm(null, true);
}

export function btnView (record:any) {
    modalType.value = 1;
    currRecord.value = record;
}

export function btnEdit (record:any) {
    modalType.value = 2;
    //record.value  =  getPersons(record.personId)
    currRecord.value = {...record};
    debugger
    validateForm(null, true);
}

export function btnDelete (record:any, call:Function) {
    Modal.confirm({
        title: '确认',
        content: `确定要删除【${record.personId}】吗？`,
        onOk: async function() {
            //await deleteEntity(record.personId);
            call();
        }
    });
}

export async function btnEditSave (call:Function) {
    if(!validateForm()) {
        return;
    }
    modalType.value = 0;
    currRecord.value = {
        ...currRecord.value,
        operatorId:localStorage.getItem("uid")
    }
    //await updateEntity(currRecord.value);
    call();
}
